package com.zjsd.mobile.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.CaptchaExpireException;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.zjsd.sqeybusiness.domain.*;
import com.zjsd.sqeybusiness.dto.CompanyInfoDTO;
import com.zjsd.sqeybusiness.dto.ProductCategoryDTO;
import com.zjsd.sqeybusiness.dto.ProductInfoDTO;
import com.zjsd.sqeybusiness.dto.ShareparamDTO;
import com.zjsd.sqeybusiness.mapper.*;
import com.zjsd.sqeybusiness.service.*;
import com.zjsd.sqeybusiness.utils.TelNoUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zheng
 */
@Api("手机端接口")
@RestController
@RequestMapping("/mobile")
public class MobileController extends BaseController {
    @Autowired
    private ICompanyInfoService companyInfoService;
    @Autowired
    private IPlatformProductCategoryService platformProductCategoryService;
    @Autowired
    private ICompanyImageService companyImageService;
    @Autowired
    private IProductCategoryService productCategoryService;
    @Autowired
    private IProductInfoService productInfoService;
    @Autowired
    private IAgencyChatService agencyChatService;
    @Autowired
    private IPrivacyPolicyService privacyPolicyService;
    @Autowired
    private IApplySampleService applySampleService;
    @Autowired
    private IShareInfoService shareInfoService ;
    @Autowired
    private ILyhfinfoService lyhfinfoService ;
    @Autowired
    private IShareLyService shareLyService ;
    @Autowired
    private TokenService tokenService;
    @Resource
    private AuthenticationManager authenticationManager;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private ISjinfoService sjinfoService; ;
    @Autowired
    private ISysAreaService sysAreaService ;
    @Autowired
    private IOrderinfoService orderinfoService ;
    @Autowired
    private IHydjinfoService hydjinfoService;
    @Autowired
    private ISysConfigService sysConfigService;
    @Autowired
    private IDzsjinfoService dzsjInfoService;
    @Autowired
    private IHyinfoService hyinfoService ;
    @Autowired
    private IRechargeinfoService rechargeinfoService;
    @Autowired
    private IOrderappealService orderappealService;
    @Autowired
    private PayBaseService payBaseService;
    @Autowired
    private DzsjinfoMapper dzsjinfoMapper;
    @Autowired
    private DzsjdetailMapper dzsjdetailMapper;
    @Autowired
    private DzsjprovincedetailMapper dzsjprovincedetailMapper;
    @Autowired
    private IRecharesettingService recharesettingService;
    @Autowired
    private IXqinfoService xqinfoService;

    /**
     * 获取广告位企业信息
     */
    @PostMapping("/queryCompanyInfo")
    //@Log(title = "Mobile-获取广告位企业信息", businessType = BusinessType.OTHER)
    public AjaxResult queryCompanyInfo(CompanyInfoDTO companyInfo)
    {
        //上架时间
        companyInfo.setShelvesStartDate(DateUtils.parseDate(DateUtils.getDate()));
        //已上架
        companyInfo.setShelvesStatus("1");
        //查询
        List<CompanyInfo> list =  companyInfoService.selectCompanyInfoForMobile(companyInfo);
        //更新企业浏览量
        /*for(CompanyInfo info:list){
            companyInfoService.updateCompanyInfoPageViews(info.getCompanyId());
        }*/
        return AjaxResult.success(list);
    }
    /**
     * 获取企业信息详细信息
     */
    //@Log(title = "Mobile-获取企业信息详细信息", businessType = BusinessType.OTHER)
    @PostMapping(value = "/getCompanyInfo")
    public AjaxResult getCompanyInfo(Long companyId)
    {
        //更新企业浏览量
        companyInfoService.updateCompanyInfoPageViews(companyId);
        return AjaxResult.success(companyInfoService.selectCompanyInfoById(companyId));
    }

    /**
     * 查询企业图片列表
     */
    //@Log(title = "Mobile-查询企业图片列表", businessType = BusinessType.OTHER)
    @PostMapping("/queryCompanyImage")
    public AjaxResult queryCompanyImage(CompanyImage companyImage)
    {
        //有效图片
        companyImage.setStatus("1");
        List<CompanyImage> list = companyImageService.selectCompanyImageList(companyImage);
        return AjaxResult.success(list);
    }

    /**
     * 查询企业产品分类列表
     */
    //@Log(title = "Mobile-查询企业产品分类列表", businessType = BusinessType.OTHER)
    @PostMapping("/queryProductCategory")
    public AjaxResult queryProductCategory(ProductCategory productCategory)
    {
        List<ProductCategoryDTO> list = productCategoryService.selectProductCategoryList(productCategory);
        return AjaxResult.success(list);
    }

    /**
     * 检索企业产品
     */
    //@Log(title = "Mobile-检索企业产品", businessType = BusinessType.OTHER)
    @PostMapping("/queryProductInfo")
    public AjaxResult queryProductInfo(ProductInfoDTO productInfoDTO)
    {
        startPage();
        productInfoDTO.setShelvesStatus("1");
        productInfoDTO.setShelvesStartDate(DateUtils.parseDate(DateUtils.getDate()));
        List<ProductInfoDTO> list = productInfoService.selectProductInfoForMobile(productInfoDTO);

        //更新浏览量
        /*for(ProductInfoDTO info:list){
            productInfoService.updateProductInfoPageViews(info.getProductId());
        }*/
        return AjaxResult.success(list);
    }

    /**
     * 获取企业产品信息详细信息
     */
    //@Log(title = "Mobile-获取企业产品信息详细信息", businessType = BusinessType.OTHER)
    @PostMapping(value = "/getProductInfo")
    public AjaxResult getProductInfo(Long productId)
    {
        //更新浏览量
        productInfoService.updateProductInfoPageViews(productId);
        return AjaxResult.success(productInfoService.selectProductInfoById(productId));
    }

    /**
     * 新增代理商在线留言
     */
    //@Log(title = "Mobile-新增代理商在线留言", businessType = BusinessType.INSERT)
    @PostMapping(value = "/saveAgencyChat")
    public AjaxResult saveAgencyChat(AgencyChat agencyChat)
    {
        return AjaxResult.success(agencyChatService.insertAgencyChat(agencyChat));
    }

    /**
     * 查询平台产品分类列表
     */
    //@Log(title = "Mobile-查询平台产品分类列表", businessType = BusinessType.OTHER)
    @PostMapping("/queryPlatformProductCategory")
    public AjaxResult queryPlatformProductCategory(PlatformProductCategory platformProductCategory)
    {
        List<PlatformProductCategory> list = platformProductCategoryService.selectPlatformProductCategoryList(platformProductCategory);
        return AjaxResult.success(list);
    }

    /**
     * 查询精品汇隐私条款
     */
    //@Log(title = "Mobile-查询精品汇隐私条款", businessType = BusinessType.OTHER)
    @PostMapping("/getPrivacyPolicy")
    public AjaxResult getPrivacyPolicy(PrivacyPolicy privacyPolicy)
    {
        List<PrivacyPolicy> list = privacyPolicyService.selectPrivacyPolicyList(privacyPolicy);
        return AjaxResult.success(list);
    }

    /**
     * 新增代理商在线留言
     */
    //@Log(title = "Mobile-样品申请", businessType = BusinessType.INSERT)
    @PostMapping(value = "/saveApplySample")
    public AjaxResult saveApplySample(ApplySample applySample)
    {
        return AjaxResult.success(applySampleService.insertApplySample(applySample));
    }


    /**
     * 查询企业信息列表
     */
    //@PreAuthorize("@ss.hasPermi('jph:companyInfo:list')")
    @ApiOperation("查询公司列表")
    //@Log(title = "Mobile-查询公司列表", businessType = BusinessType.INSERT)
    @PostMapping("/queryCompanylist")
    public TableDataInfo list(CompanyInfo companyInfo)
    {
        startPage();
        List<CompanyInfo> list = companyInfoService.selectCompanyInfoList(companyInfo);
        return getDataTable(list);
    }


    /**
     * 新增代理商在线留言
     */
    //@Log(title = "发布圈子信息", businessType = BusinessType.INSERT)
    @PostMapping ( value = "/shareInfo/addShareInfo")
    public AjaxResult add(ShareInfo shareInfo)
    {
        return toAjax(shareInfoService.insertShareInfo(shareInfo));
    }

    /**
     * 查询企业产品信息列表
     */
    //@Log(title = "查询圈子信息", businessType = BusinessType.INSERT)
    @PostMapping("/shareInfo/queryShareInfo")
    public TableDataInfo list(ShareInfo shareInfo)
    {
        startPage();
        //PageHelper.startPage(2, 2, "");
        List<ShareInfo> list = shareInfoService.selectShareInfoList(shareInfo);
        List<ShareInfo> newList = new ArrayList<ShareInfo>();
        for(ShareInfo temp: list){
            List<String>  listNum = TelNoUtil.parseTelNo(temp.getContent());
            for(String temp1:listNum){
                if(TelNoUtil.isMobileNO(temp1)){
                    temp.setContent(temp.getContent().replace(temp1,temp1.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                }
            }
            newList.add(temp);
        }
        return getDataTable(newList);
    }

    /**
     * 保存收藏、点赞信息
     */
    //@Log(title = "保存收藏、点赞信息", businessType = BusinessType.INSERT)
    @PostMapping ( value = "/shareInfo/addShareStoreInfo")
    public AjaxResult addShareStoreInfo(ShareStore shareStore)
    {
        return toAjax(shareInfoService.insertShareStoreInfo(shareStore));
    }

    /**
     * 保存收藏、点赞信息
     */
    //@Log(title = "保存收藏、点赞信息", businessType = BusinessType.INSERT)
    @PostMapping ( value = "/shareInfo/editShareReadNum")
    public AjaxResult editShareReadNum(ShareInfo shareInfo)
    {
        return toAjax(shareInfoService.updateShareReadNum(shareInfo));
    }

    /**
     * 保存留言信息
     */
    //@Log(title = "保存留言", businessType = BusinessType.INSERT)
    @PostMapping ( value = "/shareInfo/addShareLy")
    public AjaxResult addShareLy(ShareLy shareLy)
    {
        return toAjax(shareInfoService.insertShareLy(shareLy));
    }


    /**
     * 查询留言信息
     */
    //@Log(title = "查询留言信息", businessType = BusinessType.INSERT)
    @PostMapping("/shareInfo/queryShareLy")
    public TableDataInfo queryShareLy(ShareLy shareLy)
    {
        startPage();
        List<ShareLy> list = shareLyService.selectShareLyList(shareLy);
        List<ShareLy> newList = new ArrayList<ShareLy>();
        for(ShareLy temp: list){
            List<String>  listNum = TelNoUtil.parseTelNo(temp.getLynr());
            for(String temp1:listNum){
                if(TelNoUtil.isMobileNO(temp1)){
                    temp.setLynr(temp.getLynr().replace(temp1,temp1.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                }
            }

            List<Lyhfinfo> lyhfinfoList  = temp.getLyhflist() ;
            List<Lyhfinfo> lyhfinfoList1  = new ArrayList<Lyhfinfo>();
            for (Lyhfinfo lyhfTemp :lyhfinfoList){
                List<String>  listNum1 = TelNoUtil.parseTelNo(lyhfTemp.getHfnr());
                for(String temp2:listNum1){
                    if(TelNoUtil.isMobileNO(temp2)){
                        lyhfTemp.setHfnr(lyhfTemp.getHfnr().replace(temp2,temp2.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                    }
                }
                lyhfinfoList1.add(lyhfTemp);
            }
            temp.setLyhflist(lyhfinfoList1);
            newList.add(temp);
        }
        return getDataTable(newList);
    }

    /**
     * 查询我发布的信息
     */
    //@Log(title = "查询我发布的信息", businessType = BusinessType.INSERT)
    @PostMapping("/shareInfo/queryMySharedInfo")
    public TableDataInfo queryMySharedInfo(ShareInfo shareInfo)
    {
        startPage();
        List<ShareInfo> list = shareInfoService.selectMySharedInfoList(shareInfo);
        List<ShareInfo> newList = new ArrayList<ShareInfo>();
        for(ShareInfo temp: list){
            List<String>  listNum = TelNoUtil.parseTelNo(temp.getContent());
            for(String temp1:listNum){
                if(TelNoUtil.isMobileNO(temp1)){
                    temp.setContent(temp.getContent().replace(temp1,temp1.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                }
            }
            newList.add(temp);
        }
        return getDataTable(newList);
    }

    /**
     * 查询我收藏的信息
     */
    //@Log(title = "查询我收藏的信息", businessType = BusinessType.INSERT)
    @PostMapping("/shareInfo/queryMyStoredShareInfo")
    public TableDataInfo queryMyStoredShareInfo(ShareInfo shareInfo)
    {
        startPage();
        List<ShareInfo> list = shareInfoService.selectMyStoredShareInfoList(shareInfo);
        List<ShareInfo> newList = new ArrayList<ShareInfo>();
        for(ShareInfo temp: list){
            List<String>  listNum = TelNoUtil.parseTelNo(temp.getContent());
            for(String temp1:listNum){
                if(TelNoUtil.isMobileNO(temp1)){
                    temp.setContent(temp.getContent().replace(temp1,temp1.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                }
            }
            newList.add(temp);
        }
        return getDataTable(newList);    }

    /**
     * 查询我回复过的信息
     */
    //@Log(title = "查询我回复过的信息", businessType = BusinessType.INSERT)
    @PostMapping("/shareInfo/queryHasMyLyShareInfo")
    public TableDataInfo queryHasMyLyShareInfo(ShareInfo shareInfo)
    {
        startPage();
        List<ShareInfo> list = shareInfoService.selectHasMyLyShareInfoList(shareInfo);
        List<ShareInfo> newList = new ArrayList<ShareInfo>();
        for(ShareInfo temp: list){
            List<String>  listNum = TelNoUtil.parseTelNo(temp.getContent());
            for(String temp1:listNum){
                if(TelNoUtil.isMobileNO(temp1)){
                    temp.setContent(temp.getContent().replace(temp1,temp1.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")));
                }
            }
            newList.add(temp);
        }
        return getDataTable(newList);
    }

    /**
     * 获取代理商在线留言详细信息
     */
    //@Log(title = "查询代理商名称", businessType = BusinessType.INSERT)
    @PostMapping(value = "/shareInfo/queryAgencyinfo")
    public AjaxResult getAgencyinfo(Long agencyid)
    {
        return AjaxResult.success(shareInfoService.selectAgencyInfo(agencyid));
    }


    /**
     * 保存留言回复信息
     */
    //@Log(title = "保存留言回复信息", businessType = BusinessType.INSERT)
    @PostMapping ( value = "/shareInfo/addlyhfinfo")
    public AjaxResult addlyhfinfo(Lyhfinfo lyhfinfo)
    {
        return toAjax(lyhfinfoService.insertLyhfinfo(lyhfinfo));
    }
    /**
     * 查询我发布的信息
     */
    @PostMapping("/user/login")
    public AjaxResult Login(LoginInfo loginInfo)
    {
        String uuid  =  IdUtils.simpleUUID();
        String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
        String captcha = redisCache.getCacheObject(verifyKey);
        String username = loginInfo.getUsername();
        String password = loginInfo.getPassword();
        redisCache.deleteObject(verifyKey);

        Authentication authentication = null;
        try
        {
            // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
            authentication = authenticationManager
                    .authenticate(new UsernamePasswordAuthenticationToken(username, password));
        }
        catch (Exception e)
        {
            if (e instanceof BadCredentialsException)
            {
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
                throw new UserPasswordNotMatchException();
            }
            else
            {
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
                throw new CustomException(e.getMessage());
            }
        }
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        // 生成token

        String token =      tokenService.createToken(loginUser);
        AjaxResult ajax = AjaxResult.success();
        ajax.put(Constants.TOKEN, token);
        ajax.put(Constants.USERNAME,loginUser.getUser().getNickName());
        ajax.put(Constants.JWT_USERID,loginUser.getUser().getUserId());
        return ajax;
    }


    @GetMapping(value = "/querySjinfoList")
    public TableDataInfo querySjinfoList(Sjinfo sjinfo)
    {
        if(sjinfo.getHyid() != null ){
            Dzsjinfo dzsjinfo = new Dzsjinfo();
            dzsjinfo.setHyid(sjinfo.getHyid());
            List<Dzsjinfo> list = dzsjinfoMapper.selectDzsjinfoList(dzsjinfo);
            if(list != null && list.size() > 0){
                Dzsjdetail dzsjdetail = new Dzsjdetail();
                dzsjdetail.setDzsjid(list.get(0).getDzsjid());
                List<Dzsjdetail> list1 = dzsjdetailMapper.selectDzsjdetailList(dzsjdetail);
                if(list1 != null && list1.size() > 0){
                    String [] keywords = new String[list1.size()];
                    for(int i = 0 ; i < list1.size() ; i++){
                        keywords[i] = list1.get(i).getKeword();
                    }
                    sjinfo.setKewords(keywords);
                }

                Dzsjprovincedetail dzsjprovincedetail = new Dzsjprovincedetail();
                dzsjprovincedetail.setDzsjid(list.get(0).getDzsjid());
                List<Dzsjprovincedetail> list2 = dzsjprovincedetailMapper.selectDzsjprovincedetailList(dzsjprovincedetail);
                if(list2 != null && list2.size() > 0){
                    String [] princecodes = new String[list2.size()];
                    for(int i = 0 ; i < list2.size() ; i++){
                        princecodes[i] = list2.get(i).getProvincecode();
                    }
                    sjinfo.setProvincecodes(princecodes);
                }
            }
        }
        System.out.println("分页查询");
        startPage();
        List<Sjinfo> list = sjinfoService.selectSjinfoList(sjinfo);
        if(list!=null && list.size()>0){
            for(Sjinfo temp:list){
                if(StringUtils.isNotEmpty(temp.getCgrphone())){
                    //手机号后八位用星号代替
                    String cgrphone = temp.getCgrphone().replaceAll("(\\d{3})\\d{8}(\\d{0})", "$1********$2");
                    temp.setCgrphone(cgrphone);
                }
            }
        }
        return getDataTable(list);
    }

    @GetMapping(value = "/listSysarea")
    public TableDataInfo listSysarea(SysArea sysArea)
    {
        List<SysArea> list = sysAreaService.selectSysAreaList(sysArea);
        return getDataTable(list);
    }

    @GetMapping(value = "/querySjinfo")
    public AjaxResult querySjinfo(Sjinfo sjinfo)
    {
        Sjinfo sjinfo1 = sjinfoService.selectSjinfoById(sjinfo.getSjid());
        Orderinfo orderinfo = new Orderinfo();
        orderinfo.setSjid(sjinfo.getSjid());
        orderinfo.setHyid(sjinfo.getHyid());
        orderinfo.setZfzt("1");
        List<Orderinfo> orderinfoList = orderinfoService.selectOrderinfoList(orderinfo);
        if(sjinfo1 != null && StringUtils.isNotBlank(sjinfo1.getCgrphone())){
            if(orderinfoList == null || orderinfoList.size() == 0){
                //手机号后八位用星号代替
                String cgrphone = sjinfo1.getCgrphone().replaceAll("(\\d{3})\\d{8}(\\d{0})", "$1********$2");
                sjinfo1.setCgrphone(cgrphone);
            }
        }
        System.out.println("采购人手机号：" + sjinfo1.getCgrphone());
        return AjaxResult.success(sjinfo1);
    }


    @GetMapping(value = "/queryOrderinfoList")
    public TableDataInfo queryOrderinfoList(Orderinfo orderinfo)
    {
        startPage();
        List<Orderinfo> list = orderinfoService.selectOrderinfoList(orderinfo);
        return getDataTable(list);
    }

    @GetMapping(value = "/queryHydjinfoList")
    public TableDataInfo queryHydjinfoList(Hydjinfo hydjinfo)
    {
        List<Hydjinfo> list = hydjinfoService.selectHydjinfoList(hydjinfo);
        return getDataTable(list);
    }

    @GetMapping(value = "/querySysConifgByKey")
    public AjaxResult querySysConifgByKey(SysConfig sysConfig)
    {
        String name = sysConfigService.selectConfigByKey(sysConfig.getConfigKey());
        return AjaxResult.success(name);
    }

    @Transactional
    @PostMapping ( value = "/addDzsjinfo")
    public AjaxResult addDzsjinfo(Dzsjinfo dzsjinfo)
    {
        return toAjax(dzsjInfoService.insertDzsjinfo(dzsjinfo));
    }

    @GetMapping(value = "/queryDzsjinfoByHyid")
    public AjaxResult queryDzsjinfoByHyid(Dzsjinfo dzsjinfo)
    {
        Dzsjinfo dzsjinfo1 = dzsjInfoService.selectDzsjinfoByHyid(dzsjinfo.getHyid());
        return AjaxResult.success(dzsjinfo1);
    }

    @Transactional
    @PostMapping ( value = "/updateHyinfo")
    public AjaxResult updateHyinfo(Hyinfo hyinfo)
    {
        return toAjax(hyinfoService.updateHyinfo(hyinfo));
    }

    @GetMapping(value = "/getHyinfo")
    public AjaxResult getHyinfo(Hyinfo hyinfo)
    {
       Hyinfo hyinfo1 = hyinfoService.selectHyinfoById(hyinfo.getHyid());
       return AjaxResult.success(hyinfo1);
    }

    @GetMapping(value = "/queryRechargeinfoList")
    public TableDataInfo queryRechargeinfoList(Rechargeinfo rechargeinfo)
    {
        startPage();
        List<Rechargeinfo> list = rechargeinfoService.selectRechargeinfoList(rechargeinfo);
        return getDataTable(list);
    }

    @Transactional
    @PostMapping ( value = "/addOrderappeal")
    public AjaxResult addOrderappeal(Orderappeal orderappeal)
    {
        return toAjax(orderappealService.insertOrderappeal(orderappeal));
    }

    @GetMapping(value = "/queryOrderappealList")
    public TableDataInfo queryOrderappealList(Orderappeal orderappeal)
    {
        startPage();
        List<Orderappeal> list = orderappealService.selectOrderappealList(orderappeal);
        return getDataTable(list);
    }

    @Transactional
    @PostMapping ( value = "/updateOrderappeal")
    public AjaxResult updateOrderappeal(Orderappeal orderappeal)
    {
        return toAjax(orderappealService.updateOrderappeal(orderappeal));
    }

    @Transactional
    @PostMapping ( value = "/addHyinfo")
    public AjaxResult addHyinfo(Hyinfo hyinfo)
    {
        Hyinfo hyinfo1 = hyinfoService.insertHyinfoByOpenid(hyinfo);
        return AjaxResult.success(hyinfo1);
    }

    @GetMapping(value = "/queryHyinfoByOpenid")
    public AjaxResult queryHyinfoByOpenid(Hyinfo hyinfo)
    {
        Hyinfo hyinfo1 = hyinfoService.selectHyinfoByOpenid(hyinfo.getOpenid());
        return AjaxResult.success(hyinfo1);
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping ( value = "/saveOrderinfo")
    public AjaxResult saveOrderinfo(Orderinfo orderinfo,HttpServletResponse response)
    {
        String contenturl = orderinfoService.saveOrderinfo(orderinfo);
        orderinfo.setContenturl(contenturl);
        return AjaxResult.success(orderinfo);
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping ( value = "/addOrderinfo")
    public AjaxResult addOrderinfo(Orderinfo orderinfo)
    {
        Orderinfo orderinfo1  = orderinfoService.addOrderinfo(orderinfo);
        return AjaxResult.success(orderinfo1);
    }


    @PostMapping ( value = "/lakalaPayNotify")
    public void lakalaPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException
    {
         payBaseService.lakalaPayNotify(request,response);
    }


    @PostMapping ( value = "/lakalaMiniPayNotify")
    public void lakalaMiniPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException
    {
        payBaseService.lakalaMiniPayNotify(request,response);
    }

    @GetMapping(value = "/getOrderinfoByReqsn")
    public AjaxResult getOrderinfoByReqsn(Payorderinfo payorderinfo)
    {
        Payorderinfo payorderinfo1 = orderinfoService.selectOrderinfoByReqsn(payorderinfo);
        return AjaxResult.success(payorderinfo1);
    }

    /**
     * 升级会员充值
     * @param rechargeinfo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping ( value = "/saveRechargehy")
    public AjaxResult saveRechargehy(Rechargeinfo rechargeinfo)
    {
        Rechargeinfo rechargeinfo1 = rechargeinfoService.saveRechargeinfo(rechargeinfo);
        return AjaxResult.success(rechargeinfo1);
    }

    /**
     * 充值
     * @param rechargeinfo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping ( value = "/saveRecharge")
    public AjaxResult saveRecharge(Rechargeinfo rechargeinfo)
    {
        Rechargeinfo rechargeinfo1 = rechargeinfoService.saveRecharge(rechargeinfo);
        return AjaxResult.success(rechargeinfo1);
    }

    @GetMapping(value = "/getShareparam")
    public AjaxResult getShareparam(ShareparamDTO shareparamDTO) throws IOException {
        ShareparamDTO shareparamDTO1 = sjinfoService.getShareparam(shareparamDTO);
        return AjaxResult.success(shareparamDTO1);
    }

    @GetMapping(value = "/queryRecharsetting")
    public TableDataInfo queryRecharsetting(Recharesetting recharesetting)
    {
        List<Recharesetting> list = recharesettingService.selectRecharesettingList(recharesetting);
        return getDataTable(list);
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping ( value = "/addXqinfo")
    public AjaxResult addXqinfo(Xqinfo xqinfo)
    {
        int count = xqinfoService.insertXqinfo(xqinfo);
        return toAjax(count);
    }
}
